import Vue from 'vue'
import App from './App'
import VueClipboard from 'vue-clipboard2'
import store from "./store";
import toast from './components/Loading/index.vue'
import VueI18n from 'vue-i18n';
import en from './lang/en';
Vue.component('toast', toast)
Vue.prototype.$store = store;

Vue.prototype.ScanAudio = function(data){
        let music = null;
		console.log('创建')
        music = wx.createInnerAudioContext(); //创建播放器对象
		music.obeyMuteSwitch = false
		music.src= "/static/warn.wav"; //选择播放的音频
		music.onPlay(() => {
		  plus.push.createMessage("已抢到"+data.order.order_sn+"订单");
		  console.log('开始播放');
		});
		music.onError(e => {
		  console.log('onError')
		  console.log(e);
		});
		console.log('选择路径');
        music.play(); //执行播放
}
Vue.use(VueI18n)
const lang ='en'
const i18n = new VueI18n({
  locale: lang,
  messages: {
		'en':en
  }
})

Vue.prototype._i18n = i18n
function loading(tf) {
	if (tf) {
		store.commit("switch_loading", tf)
	} else {
		store.commit("switch_loading")
	}
}
Vue.prototype.$loading = loading;
Vue.use(VueClipboard)
//控制富文本中图片大小
Vue.filter('formatRichText', function (html) {
	if(!html) return	
	let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
		match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
		match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
		match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
		return match;
	});
	newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
		match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
		return match;
	});
	newContent = newContent.replace(/<br[^>]*\/>/gi, '');
	newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:10px auto;"');
	return newContent;
})
const currentVersion = {
	id: 0
}
try {
	const version = uni.getStorageSync('version');
	if (version) {
		currentVersion.id = version;
	}
} catch (e) {
	currentVersion.id = 0;
}

Vue.prototype.$current = currentVersion
Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	i18n,
	...App
})
app.$mount()
export default app
